App.controller('taskDetailController', ['$scope', '$state', '$stateParams', 'Page', function($scope, $state, $stateParams, Page) {

	//var date = new Date();
	//var now = date.getFullYear() + "-" + ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : '0' + (date.getMonth() + 1))
	//	+ "-" + (date.getDate() > 9 ? date.getDate() : '0' + date.getDate()) ;
	//$scope.uploadTime = now;
    //

	Page.ajaxPostQuiet('media/bus/companys.do', null, function (resp) {
		$scope.companys = resp.data;
	});

	$scope.$watch('taskItemGrid.checkRadio', function (newValue, oldValue, $scope) {
		if(newValue){
			$scope.basicItemType = newValue;
			designColDefs(newValue);
		}
	});

	$scope.checkResultGrid = {

	};


	$scope.taskItemGrid = {
		checkResult : function(row) {
			//$scope.checkResultModal.taskId = row.taskId;
			Page.ajaxPostQuiet('checkTask/checkResult.do', {taskId : row.taskId, itemId : row.itemId}, function (resp) {
				$scope.checkHeads = resp.data.checkHeads;
				$scope.checkDatas = resp.data.checkDatas;
				$scope.checkResultModal.show();
			});
		}
	};
	$scope.$on('$viewContentLoaded', function() {
		$scope.taskTypes=[{
			name : '车辆', value : '1'
		},{
			name : '站点', value : '2'
		},{
			name : '广告', value : '3'
		}]

		$scope.basicItemType = $scope.taskTypes[0].value;
		designColDefs($scope.basicItemType);
	});
    //
	$scope.dynamicQuery = function() {
		var queryTaskType;
		if($scope.taskItemGrid.query.taskType != undefined &&  $scope.taskItemGrid.query.taskType != "") {
			queryTaskType = $scope.taskItemGrid.query.taskType;
		} else {
			queryTaskType = $scope.basicItemType;
		}
		designColDefs(queryTaskType);
	};

	$scope.checkResultModal = {
		taskId : '',
		onShow : function() {

		},
		onOkClick : function() {

		},
		onHidden : function() {

		}
	};

	function designColDefs(taskType) {
		var column_defs = [
			{
				buttons: [
					{
						name: '检查结果',
						class: 'btn-edit',
						icon: 'glyphicon glyphicon-pushpin',
						event: 'checkResult'
					}
					//,
					//{
					//	name: '资源检查',
					//	class: 'btn btn-success',
					//	icon: 'glyphicon glyphicon-pushpin',
					//	event: 'resouceCheck'
					//}
				]
			}
		];

		if(taskType == "1") {
			column_defs[0].target = 6;
		} else if(taskType == "2") {
			column_defs[0].target = 5;
		}

		$scope.taskItemGrid.column_defs = column_defs;
		$scope.taskItemGrid.setDynamicTable('checkTask/dynamicHead.do',{taskType : taskType});

	}
    //
	//$scope.$watch('stopCheck.imgFiles.length',function(newValue,oldValue, scope){
	//	if(newValue != undefined) {
	//		setTimeout(function(){
	//			if($scope.stopCheck.imgFiles.length > 0) {
	//				for (var i = 0; i < $scope.stopCheck.imgFiles.length; i++) {
	//					if($scope.stopCheck.imgFiles[i].type != "bmp" && $scope.stopCheck.imgFiles[i].type != "gif"
	//						&& $scope.stopCheck.imgFiles[i].type != "png" && $scope.stopCheck.imgFiles[i].type != "jpg"
	//						&& $scope.stopCheck.imgFiles[i].type != "jpeg") {
	//						Page.notice("请上传图片!");
	//						$scope.copyResCheck = {};
	//						$scope.stopCheck.imgFiles.splice(i,1);
	//						return;
	//					}
	//				}
	//				if($scope.stopCheck.imgFiles.length > 0) {
	//					$scope.copyResCheck = angular.copy($scope.stopCheck);
	//					$scope.$apply($scope.copyResCheck);
	//				}
	//			}
	//		},200)
	//	}
	//});
    //
	//$scope.$watch('adCheck.files.length',function(newValue,oldValue, scope){
	//	if(newValue != undefined) {
	//		setTimeout(function(){
	//			if($scope.adCheck.files.length > 0) {
	//				for (var i = 0; i < $scope.adCheck.files.length; i++) {
	//					if($scope.adCheck.files[i].type != "bmp" && $scope.adCheck.files[i].type != "gif"
	//						&& $scope.adCheck.files[i].type != "png" && $scope.adCheck.files[i].type != "jpg"
	//						&& $scope.adCheck.files[i].type != "jpeg") {
	//						Page.notice("请上传图片!");
	//						$scope.copyAdCheck = {};
	//						$scope.adCheck.files.splice(i,1);
	//						return;
	//					}
	//				}
	//			}
	//			if($scope.adCheck.files.length > 0) {
	//				$scope.copyAdCheck = angular.copy($scope.adCheck);
	//				$scope.$apply($scope.copyAdCheck);
	//			}
	//		},200)
    //
	//	}
	//});
    //
    //
	//$scope.deleteImg = function(value) {
	//	for (var i = 0; i < $scope.copyResCheck.imgFiles.length; i++) {
	//		if($scope.copyResCheck.imgFiles[i].path == value.path ) {
	//			$scope.copyResCheck.imgFiles.splice(i,1);
	//			$scope.stopCheck.imgFiles.splice(i,1);
	//		}
	//	}
	//	if($scope.copyResCheck.imgFiles.length == 0) {
	//		$scope.copyResCheck.result = "";
	//		$scope.copyResCheck.comment = "";
	//	}
	//}
    //
	//$scope.checkStopResourceModal = {
	//	onOkClick : function() {
	//		if($scope.copyResCheck == undefined || $scope.copyResCheck.imgFiles == undefined || $scope.copyResCheck.imgFiles.length == 0) {
	//			Page.notice("您还未上传图片!");
	//			return;
	//		}
	//		if(!$scope.resourceValidateForm.$valid) {
	//			$scope.resourceValidateForm.doValidate();
	//		} else {
	//			Page.ajaxGetQuiet('mediaCheck/saveResourceImgs.do', {dataId : $scope.copyResCheck.resourceId,
	//				files : $scope.copyResCheck.imgFiles,result : $scope.copyResCheck.result,
	//				comment : $scope.copyResCheck.comment,sourceType : '2'}, function (resp) {
	//				Page.notice("提交成功!");
	//				$scope.checkStopResourceModal.hide();
	//			});
	//		}
    //
	//	},
	//	onHidden : function() {
	//		$scope.stopCheck.imgFiles = [];
	//		$scope.copyResCheck = {};
	//	}
	//}
    //
	//$scope.checkStopAdModal = {
	//	onOkClick : function() {
	//		if($scope.copyAdCheck == undefined || $scope.copyAdCheck.files == undefined || $scope.copyAdCheck.files.length == 0) {
	//			Page.notice("您还未上传图片!");
	//			return;
	//		}
	//		if(!$scope.adValidateForm.$valid) {
	//			$scope.adValidateForm.doValidate();
	//		} else {
	//			Page.ajaxGetQuiet('mediaCheck/saveResourceImgs.do', {dataId : $scope.copyAdCheck.makeBillId,
	//				resourceId : $scope.copyAdCheck.resourceId,publishDetailId : $scope.copyAdCheck.id,
	//				files : $scope.copyAdCheck.files,result : $scope.copyAdCheck.result,
	//				comment : $scope.copyAdCheck.comment,sourceType : '3'}, function (resp) {
	//				Page.notice("提交成功!");
	//				$scope.checkStopAdModal.hide();
	//			});
	//		}
    //
	//	},
	//	onHidden : function() {
	//		$scope.adCheck.files = [];
	//		$scope.copyAdCheck = {};
	//	}
	//}

	//changeListType = function(taskType) {
	//	console.log(taskType + "231321321321");
	//}
    //
	//function changeListType(taskType) {
	//	console.log(taskType);
	//}
}]);


